package net.muchine.core.support.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import net.muchine.core.support.annotation.PasswordConfirm;
import net.muchine.web.front.forms.Password;

public class PasswordConfirmationValidator implements ConstraintValidator<PasswordConfirm, Password> {

	public void initialize(PasswordConfirm constraintAnnotation) {
		
	}

	public boolean isValid(Password password, ConstraintValidatorContext context) {
		if (password == null) return true;
		
		String newPassword = password.getNewPassword();
		String newPasswordConfirmation = password.getNewPasswordConfirmation();
		
		if (newPassword == null) return true;

		return newPassword.equals(newPasswordConfirmation);
	}
}
